package homework023;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;

@Test
public class Main {
    public static void main(String[] args) throws ClassNotFoundException, InvocationTargetException, IllegalAccessException {

        Class<?> aClass = Class.forName("demo3.Testing");

        Method[] methods = aClass.getMethods();

        for (Method method : methods) {
            // 如果该类属于demo3.Testing，才是我们需要调用的
            if ("demo3.Testing".equals(method.getDeclaringClass().getName())) {
                System.out.println(method.getName());

                Parameter[] parameters = method.getParameters();
                int length = parameters.length;

                // 根据参数长度，决定调用时要不要传参
                if (length > 0) {
                    method.invoke(new Testing(), "我是入参");
                } else {
                    method.invoke(new Testing());
                }

            }

        }

    }
}
